//

import UIKit

class WP_MonthDetailViewController: WP_BasicViewController {
    
    var model:MonthModel!
    var ID:String?
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(true)
         WP_CoreDataModel.coreDataManager.setEntityName(text: "MonthModel")
        
        getData()
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        weak var weakSelf = self
        self.setupRightSetting("Edit") {
            let vc = WP_MonthlyAddViewController()
            vc.model = weakSelf!.model
            weakSelf?.navigationController?.pushViewController(vc, animated: true)
        }
        // Do any additional setup after loading the view.
        self.setNavTitle("Detail")
        self.view.addSubview(monthTableView)
    }
    lazy var monthTableView:UITableView = {
        let tableview = UITableView(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: kScreenHeight), style: .plain)
        tableview.delegate = self
        tableview.dataSource = self
        tableview.tableFooterView = UIView()
        tableview .register(WP_DetailLabelTableViewCell.classForCoder(), forCellReuseIdentifier:NSStringFromClass(WP_DetailLabelTableViewCell.classForCoder()))
        tableview.separatorColor = UIColor.white
        tableview.rowHeight = UITableView.automaticDimension
        tableview.estimatedRowHeight = 100
        return tableview
        
    }()
    lazy var dataArr:[Any] = {
        let arr = Array<Any>()
        return arr
    }()
    func getData()  {
        
         WP_CoreDataModel.coreDataManager.readData(sequenceKeys: Array(), ascending: false, filterStr: "iD=\(ID!)", success: { (arr) in
            
            if arr.isEmpty {return}
            
            model = arr.last as? MonthModel
            monthTableView.reloadData()
            
        }, fail: {})
    }
    
    /*
     // MARK: - Navigation
     
     // In a storyboard-based application, you will often want to do a little preparation before navigation
     override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
     // Get the new view controller using segue.destination.
     // Pass the selected object to the new view controller.
     }
     */
    
}
extension WP_MonthDetailViewController:UITableViewDelegate,UITableViewDataSource {
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 5
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let cell:WP_DetailLabelTableViewCell = tableView.dequeueReusableCell(withIdentifier: NSStringFromClass(WP_DetailLabelTableViewCell.classForCoder()), for: indexPath) as! WP_DetailLabelTableViewCell
        cell.selectionStyle = .none
        //        if !dataArr.isEmpty {
        //            let models = dataArr[indexPath.row] as! DayModel
        //
        //        }
        
        switch indexPath.row {
        case 0:
            cell.titleLabel.text = "Work done today"
            cell.contentLabel.text = model.finish
            
        case 1:
            cell.titleLabel.text = "Unfinished business today"
            cell.contentLabel.text = model.unfinish
            
        case 2:
            cell.titleLabel.text = "Job summary"
            cell.contentLabel.text = model.summary
            
        case 3:
            cell.titleLabel.text = "Work plan for next month"
            cell.contentLabel.text = model.plan
            
        case 4:
            cell.titleLabel.text = "Remarks"
            cell.contentLabel.text = model.remark
            
        default:
            break
        }
  
        return cell
    }
    
    
    
    
}
